package com.cyys.modules.generator.model;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cyys.common.model.BaseBean;
import com.cyys.common.utils.StringUtil;
import com.cyys.modules.core.sysParam.ParamBasicUtil;
import com.cyys.modules.core.sysParam.ParamConstants;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.io.File;
import java.util.List;
import java.util.regex.Matcher;

@Data
@TableName("generator_table")
public class GeneratorTable extends BaseBean {

	@TableField(condition = SqlCondition.LIKE)
	private String tableName;  //数据库表名  generator_table

	private String tableComment;  //java生成类注释

	private String className;  //java生成类名称  generatorTable

	private String moudleName;  //模块名称  generator

	private String shiro; //权限

	private String fileDirName;//文件夹名 table

	private String isAlready;//是否已执行过

	private String modelInherits; //model继承类 CoreUserBean,CoreBean,BaseBean

	private String pageModel; //页面模板 1、普通页面；2、树形页面

	private String needFile; //需要生成的文件，1，mapper，2、model，3、dao;4、service;5、action;6、list；7、input

	@TableField(updateStrategy = FieldStrategy.IGNORED)
	private String menuParentId; //生成菜单编号 //默认null不生成

	@TableField(exist = false)
	private List<GeneratorField> fieldList;

	@TableField(exist = false)
	private String upperClassName;   //类大写名称

	@TableField(exist = false)
	private String fileDirNameSeparator; //将文件夹中的点换成/

	@TableField(exist = false)
	private String inputTypes;   //包含的数据类型

	@TableField(exist = false)
	private List<String> paramNameList; //系统的参数名称

	@TableField(exist = false)
	private int hasQuery; //是否要查询

	@JsonIgnore
	public String getFileDirNameSeparator() {
		if(StringUtil.isNotEmpty(fileDirName))
			return fileDirNameSeparator = fileDirName.replaceAll("\\.", Matcher.quoteReplacement(File.separator));
		return "";
	}

	@JsonIgnore
	public String getUpperClassName() {
		if(StringUtil.isNotEmpty(className))
			return StringUtil.upperCaseFirst(className);
		return "";
	}

	@JsonIgnore
	public String getPageModelName() {
		if(StringUtil.isNotEmpty(pageModel))
			return ParamBasicUtil.getParamBasicTypeMap().get(ParamConstants.PAGE_MODEL).get(pageModel);
		return "";
	}

	@JsonIgnore
	public String getIsAlreadyName() {
		if(StringUtil.isNotEmpty(isAlready))
			return ParamBasicUtil.getParamBasicTypeMap().get(ParamConstants.YES_NO).get(isAlready);
		return "";
	}

	@JsonIgnore
	public String getNeedFileName() {
		if(StringUtil.isNotEmpty(needFile)){
			String[] needFiles = needFile.split(",");
			String needFileName = new String();
			for (String fileName: needFiles) {
				needFileName +=ParamBasicUtil.getParamBasicTypeMap().get(ParamConstants.GENERATOR_NEED_FILE).get(fileName);
				needFileName += ",";
			}
			needFileName = needFileName.substring(0,needFileName.lastIndexOf(","));
			return needFileName;
		}
		return "";
	}

}
